package com.example.stock.excel.finance;

import com.example.stock.excel.ExcelReaderUtil;
import com.example.stock.util.DataUtil;
import lombok.extern.log4j.Log4j2;
import java.util.List;
import java.util.Objects;

@Log4j2
public class FinanceDataUtils {

    // 营业总收入
    static List<TotalOperatingRevenue> totalOperatingRevenueList;

    // ROE
    static List<Roe> roeList;

    // 扣非净利润
    static List<AdjustedProfit> adjustedProfitList;

    // 毛利率
    static List<GrossProfitMargin> grossProfitMarginList;

    // 净利率
    static List<NetProfitMargin> netProfitMarginList;

    // 负债率
    static List<LiabilityOnAssetRatio> liabilityOnAssetRatioList;

    //  营业总收入同比增长率(%)
    static List<IncTotalRevenueYearOnYear> incTotalRevenueYearOnYearList;

    public static List<IncTotalRevenueYearOnYear> getIncTotalRevenueYearOnYearList() {
        if (incTotalRevenueYearOnYearList == null) {
            incTotalRevenueYearOnYearList = getList(IncTotalRevenueYearOnYear.class, "inc_total_revenue_year_on_year");
        }
        return incTotalRevenueYearOnYearList;
    }

    public static List<TotalOperatingRevenue> getTotalOperatingRevenueList() {
        if (Objects.isNull(totalOperatingRevenueList)) {
            totalOperatingRevenueList = getList(TotalOperatingRevenue.class, "total_operating_revenue");
        }
        return totalOperatingRevenueList;
    }

    public static List<Roe> getRoeList() {
        if (Objects.isNull(roeList)) {
            roeList = getList(Roe.class ,"roe");
        }
        return roeList;
    }

    public static List<AdjustedProfit> getAdjustedProfitList() {
        if (Objects.isNull(adjustedProfitList)) {
            adjustedProfitList = getList(AdjustedProfit.class,"adjusted_profit");
        }
        return adjustedProfitList;
    }

    public static List<GrossProfitMargin> getGrossProfitMarginList() {
        if (Objects.isNull(grossProfitMarginList)) {
            grossProfitMarginList = getList(GrossProfitMargin.class,"gross_profit_margin");
        }
        return grossProfitMarginList;
    }

    public static List<NetProfitMargin> getNetProfitMarginList() {
        if (Objects.isNull(netProfitMarginList)) {
            netProfitMarginList = getList(NetProfitMargin.class,"net_profit_margin");
        }
        return netProfitMarginList;
    }

    public static List<LiabilityOnAssetRatio> getLiabilityOnAssetRatioList() {
        if (Objects.isNull(liabilityOnAssetRatioList)) {
            liabilityOnAssetRatioList = getList(LiabilityOnAssetRatio.class,"liability_on_asset_ratio");
        }
        return liabilityOnAssetRatioList;
    }

    private static <T> List<T> getList(Class<T> tClass, String sheetName) {
        return DataUtil.getListData(tClass, ExcelReaderUtil.FILE_STOCK_FINANCE, sheetName);
    }
}
